package com.sjl.mapper;

import com.sjl.springboot.domain.page.PageQuery;
import com.sjl.springboot.domain.user.SysUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserMapper {
    /**
     * 无条件查询所有用户列表
     *
     * @return 所有列表
     */
    @Select("SELECT  * FROM  sys_user LIMIT 0,100")
    @Results(id = "sysUser", value = {@Result(column = "user_id", property = "userId"),
            @Result(column = "dept_id", property = "deptId"),
            @Result(column = "login_name", property = "loginName"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "user_type", property = "userType"),
            @Result(column = "email", property = "email"),
            @Result(column = "phonenumber", property = "phonenumber"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "avatar", property = "avatar"),
            @Result(column = "password", property = "password"),
            @Result(column = "salt", property = "salt"),
            @Result(column = "status", property = "status"),
            @Result(column = "del_flag", property = "delFlag"),
            @Result(column = "login_ip", property = "loginIp"),
            @Result(column = "login_date", property = "loginDate"),
            @Result(column = "create_by", property = "createBy"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_by", property = "updateBy"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "remark", property = "remark")}
    )
    List<SysUser> findAllUsers();

    /**
     * 分页查询用户
     * @param pageQuery
     * @return 分页数据
     */
    @Select("select * from sys_user")
    @ResultMap(value = "sysUser")
    List<SysUser> findPageUsers(PageQuery<SysUser> pageQuery);

    /**
     * 更新用户
     * @param sysUser 用户实体
     * @return 更新条数
     */
    int updateUser(SysUser sysUser);

    /**
     * 根据ID 查询用户详情
     * @param id
     * @return
     */
    @Select("SELECT  * FROM  sys_user where user_id =#{id}")
    @ResultMap(value = "sysUser")
    SysUser findUserById(@Param("id") String id);

    /**
     * 根据名称 查询用户详情
     * @param name 登录名
     * @return
     */
    @Select("select * from sys_user where login_name=#{name}")
    @ResultMap(value = "sysUser")
    SysUser finUserByName(@Param("name") String name);
}
